﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Cognitum.CassandraTableStorage.Extensions
{
    public static class PropertyNameExtensions
    {
        //From http://py-sty.blogspot.com/2011/04/getting-net-property-names-without.html
        public static string PropertyName<T, TReturn>(this T obj, Expression<Func<T, TReturn>> property) where T : class
        {
            MemberExpression body = (MemberExpression)property.Body;
            if (body == null)
                throw new ArgumentException("The provided expression did not point to a property.");

            return body.Member.Name;
        }
    }
}